package main

import (
	"gorm.io/driver/mysql"
	"gorm.io/gen"
	"gorm.io/gorm"
)

func main() {
	// Initialize the generator with configuration
	g := gen.NewGenerator(gen.Config{
		OutPath:       "query", // output directory, default value is ./query
		Mode:          gen.WithDefaultQuery | gen.WithQueryInterface,
		FieldNullable: true,
	})

	var dsn = "root:root@tcp(golanghost:3306)/go-sql?parseTime=true&loc=Local"
	// Initialize a *gorm.DB instance
	db, _ := gorm.Open(mysql.Open(dsn))

	// Use the above `*gorm.DB` instance to initialize the generator,
	// which is required to generate structs from db when using `GenerateModel/GenerateModelAs`
	g.UseDB(db)

	g.ApplyBasic(
		g.GenerateModel("sys_audit_logs"),
		g.GenerateModel("sys_config"),
		g.GenerateModel("sys_departments"),
		g.GenerateModel("sys_menus"),
		g.GenerateModel("sys_permissions"),
		g.GenerateModel("sys_role_custom_data_scopes"),
		g.GenerateModel("sys_role_permissions"),
		g.GenerateModel("sys_roles"),
		g.GenerateModel("sys_user_roles"),
		g.GenerateModel("sys_users"),
	)

	// Execute the generator
	g.Execute()
}
